package com.jdiv.internalClasses;

import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;

public class Character {

	public Pixmap pixmap;
	public TextureRegion region;
	public int width;
	public int height;
	public int yOffset;
	public int fileOffset;

	public Character(int width, int height, int yOffset, int fileOffset) {
		this.width = width;
		this.height = height;
		this.yOffset = yOffset;
		this.fileOffset = fileOffset;
		if (this.width > 0 && this.height > 0) {
			pixmap = new Pixmap(this.width, this.height, Format.RGBA8888);
		}
	}

	public void createRegion() {
		
		if (this.width > 0 && this.height > 0) {
			int w = this.obtenerSiguientePotenciaDe2(this.width);
			int h = this.obtenerSiguientePotenciaDe2(this.height);
			int tam = (w > h) ? w : h;
			System.out.println("-->" + tam + "-->" + this.width + "x" + this.height);
			Pixmap pix = new Pixmap(tam, tam, Format.RGB888);
			pix.drawPixmap(pixmap, 0, 0);
			Texture tex = new Texture(pix);
			region = new TextureRegion(tex, 0, 0, this.width, this.height);
		}
		
	}
	
	public int obtenerSiguientePotenciaDe2(int n) {
		
		float p = (float) (Math.log10(n)/Math.log10(2));
		p+= (p - (int) p) > 0 ? 1: 0;
		int pow = (int) Math.pow(2, (int)p);
		
		return pow;
		
	}
	
}
